# Message - Backend components communicate using messages
# Copyright (C) 2007 Lauri Taimila
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

__licence__ = "GPLv2"
__copyright__ = "2007, Lauri Taimila"
__author__ = "Lauri Taimila <lauri@taimila.com>"

class Message:
    """
    Backend components uses Messages to communicate with each other.
    
    Message has two internal data fields: type and data. Type determines what
    kind of message this is. MessageHandlers can read type with get_type()
    method and act differently on different messages. Message can also include
    extra data object, but ths is optional. MessageHandler can get data with
    get_date() method.
    """
    
    def __init__(self, message_type, message_data = None):
        """
        Create a new Message object with given type and data
        """
        self.message_type = message_type # MessageType constant. MessageHandlers use this to detect message's type.
        self.message_data = message_data # Message data object. Messages can contain extra data.
        
    def get_type(self):
        """
        Get message type
        @return: Message type as integer (see message_type_priority.py)
        """
        return self.message_type
        
    def get_data(self):
        """
        Get message data. Return None if there is no data
        @return: Userdata or None if there data is not set 
        """
        return self.message_data
